<?php

namespace App\Http\Middleware;

use Closure;

class AdminMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $adminInfo = session('adminInfo');

        if($adminInfo->role != 'admin'){
            return response()->json(['status' => 0, 'msg' => '你没有权限操作']);
        }

        return $next($request); 
    }
    //
    // public function handle($request, Closure $next)
    // {
    //     $adminInfo = session('adminInfo');

    //     $userInfo = DB::table('users')->where('id', $adminInfo->id)->select('role')->first();

    //     if($userInfo->role != 'admin'){
    //         return response()->json(['status' => 0, 'msg' => '你没有权限操作']);
    //     }

    //     return $next($request); 
    // }
}
